
from app import BASC_URL


class Login_api():
    def __init__(self):
        self.get_img_url=BASC_URL+"/common/public/verifycode1/{}"
        self.get_msg_url = BASC_URL + "/member/public/sendSms"
        self.reg_url = BASC_URL + "/member/public/reg"
        self.login_url = BASC_URL + "/member/public/login"
    def get_img_code(self,session,r):
        """定义获取图片验证码接口方法"""
        url=self.get_img_url.format(r)
        #导入session发送请求
        response=session.get(url)
        return response
    def get_msg_code(self,session,phone,imgcode):
        """获取短信验证码接口"""
        form_data={'phone':phone,'imgVerifyCode':imgcode,'type':'reg'}
        resp=session.post(self.get_msg_url,form_data)
        return resp
    def register_api(self,session,phone,pwd='test123',imgcode='8888',phone_code='666666',dy_server='on',invite_phone=""):
        """定义注册接口"""
        form_data={"phone": phone,
                     "password": pwd,
                     "verifycode": imgcode,
                     "phone_code": phone_code,
                     "dy_server": dy_server,
                    "invite_phone":invite_phone}
        resp=session.post(self.reg_url,form_data)
        return resp
    def login_api(self,session,phone,pwd="test123"):
        """定义登录接口"""
        login_data={"keywords":phone,"password":pwd}
        resp=session.post(self.login_url,data=login_data)
        return resp




